package com.itheima.homework5;

import java.util.Scanner;
import java.util.TreeSet;

public class GetNewString {
    public static void main(String[] args) {
        //键盘录入一段字符串并遍历存入字符数组
        char[] charArray = getChars();
        //将每个字符添加到TreeSet<Character> ts中
        TreeSet<Character> ts = getCharTs(charArray);
        //创建StringBuilder将每个字符拼接到一个字符串中
        String s1 = getString(ts);
        System.out.println(s1);
    }

    private static String getString(TreeSet<Character> ts) {
        StringBuilder b = new StringBuilder();
        String s1 = "";
        for (Character t : ts) {
            s1 = b.append(t).toString();
        }
        return s1;
    }

    private static TreeSet<Character> getCharTs(char[] charArray) {
        TreeSet<Character> ts = new TreeSet<>();
        for (int i = 0; i < charArray.length; i++) {
            ts.add(charArray[i]);
        }
        return ts;
    }

    private static char[] getChars() {
        System.out.println("请输入一段字符串");
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        return s.toCharArray();
    }
}
